package com.solvePlat.service.Impl;

import com.solvePlat.dao.CommentGiveUpInfoMapper;
import com.solvePlat.entity.CommentGiveUpInfo;
import com.solvePlat.shiro.JWTToken;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.UUID;

@Service
public class CommentGiveUpInfoServiceImpl {

    @Resource
    private CommentGiveUpInfoMapper commentGiveUpInfoMapper;

    public void addCommentGiveUpInfo(CommentGiveUpInfo commentGiveUpInfo){
            JWTToken jwtToken = (JWTToken) SecurityUtils.getSubject().getPrincipal();
            LocalDateTime localDateTime = LocalDateTime.now();
            ZoneId zone = ZoneId.systemDefault();
            Instant instant = localDateTime.atZone(zone).toInstant();
            Date date = Date.from(instant);

            commentGiveUpInfo.setUuid(UUID.randomUUID().toString());
            commentGiveUpInfo.setCreateTime(date);
            commentGiveUpInfo.setCreatorId(jwtToken.getUserId());
            commentGiveUpInfoMapper.insert(commentGiveUpInfo);
        }
}
